<fieldset>
  
    <div class="widget">
    <div class="head"><h5 class="iHome">Create category</h5></div>
   {{ form_start(form, {'attr': {'class': 'mainForm', 'id': idform }}) }}
    <div class="rowElem">
       
        <label>Select country</label>
        <div class="formRight">                            
                            {{ form_widget(form.geo)}}
        </div>
       </div>
<div class="rowElem" >
    
<label>Select language:</label>
                    	
	<div class="formRight" id="lang_list_div">                            
            <select data-placeholder="Select languages" style="display:none" class="chzn-select" multiple="multiple" tabindex="-1" name="lang[]" id="lang_list" >
              
                {%for lang in languages%}
                {% set value = '' %}
                {% if languages_selected is defined %}
                {%for selected  in languages_selected%}
                {% if selected ==lang.id %}
                {% set value = 'selected' %}
                {% endif %}
                {% endfor %}
                {% endif %}
                    <option value="{{lang.id}}" {{value}}>{{lang.name}}</option>
                {% endfor %}
            </select>   
        </div>
</div>
   <div class="fix"></div>
  
   <div class="rowElem">
      <div id="button_div"> <input type="submit" id="valid_button" value="Link languages"></div>
   </div>
    {{ form_end(form) }}          
  
   </div>
</fieldset>
<script>
$( "#create" ).submit(function( event ) {
 
 var action= '{{path('em_geography_language_save_selection')}}';
 var datos = $(this).serialize();     
 console.log(datos);

 $.ajax({type: 'POST', url:action, script:true, cache:false,data: datos,
                   // beforeSend: function(response){ $('#formcontent').html('<div align="center"><img src="{{asset('bundles/news/images/loaders/loader8.gif')}}" alt="" class="p12"><br>Loading data...</div>');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){

			}else{
                      //  console.log(response);
                        $('#tablelangs').html(response);
                        
			}
                } });
        return false;
 
 
});


$( "#update" ).submit(function( event ) {
if($("#lang_list").val()===null){
  $("#lang_list_div").append('<label for="req" generated="true" class="error">This field is required</label>');
  return false;
}
 
 
var action='{{ path('em_lang_relation_update')}}';   
//action=action.replace("data",$('#geo_id').val());
var datos = $(this).serialize();  
 $.ajax({type: 'POST', url:action, script:true, cache:false,data: datos,
                    beforeSend: function(response){ $('#button_div').append('  <div id="loader"><img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt=""></div>');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){

			}else{
                     
                       $('#tablelangs').html(response);
                       $('#loader').remove();
                        
			}
                } });
 return false;
});


$(".chzn-select").chosen(); 
    
$('#tags').tagsInput({width:'100%'});

$("#lang_form_geo").on('change', function() {
//alert(this.value);
if(this.value!==""){
var action='{{ path('em_lang_relation_find',{'id':'data'}) }}';   
action=action.replace("data",this.value);

 //console.log(action);   
 $.ajax({type: 'POST', url:action, script:true, cache:false,
                    beforeSend: function(response){ $('#button_div').html('<img src="{{asset('bundles/news/images/loaders/loader.gif')}}" alt="">');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){

			}else{
                     // console.log(response.language);
                     
                       $('#combo').html(response);
                       $("select#lang_form_geo").uniform();
                      // $("select#lang_form_geo").val('25').change();
                        
			}
                } });
            }
        return false;

});
</script>
